import React from 'react'
// 函数组件没有生命周期
import {useEffect,useState} from "react" // useEffect用来模拟生命周期
function Appfn() {
  let [name,setNmae] = useState("zhangsan")
  let [num,setNum] = useState(0)
  useEffect(()=>{
        console.log("我执行了");
        return ()=>{
            console.log("我相当于类组件得componentWillUnmount","组件卸载的生命周期")
        }
  },[num])
  // useEffect的依赖项为空数组的时候，相当于componentDidMount,
  // useEffect 第二个参数有依赖项的时候可以理解为componentDidUpdate，
  // 相当于vue里的watch
  let fn = ()=>{
      setNum(num=>num+1 )
  }
  return (
    <div>
        <span id='aaa'>{num}</span>
        <button onClick={fn}>修改name</button>
    </div>
  )
}

export default Appfn